package com.rentplant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rentplant.Pojo.item;
import com.rentplant.Pojo.user;
import com.rentplant.service.impl.itemServiceImp;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Rollback(value = false)
@RunWith(SpringRunner.class)
public class submitItem extends ApplicationTest {
    @Autowired
    private itemServiceImp itemserviceimp;

    @Test
    public void test(){
        System.out.println("待插入的物品数据");
        item iteminfo = new item("i1111111111","测试物品","测试物品介绍","['http://127.0.0.1:8080/image/download?name=c0408012-219e-44ce-8fd0-f7763faa24b8.jpg']",
                "2023-04-04",100,200,50,0,"待审核","1000000","20190200452","1221212",
                "012","品质生活","是","江西省九江是联系我去","xidnjgndfi-asdnjkcnxv");
        JSONObject item = (JSONObject) JSON.toJSON(iteminfo);
//        对应sql使用的数据属性名
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("itemID","itemid"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("itemTitle","title"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("itemInfo","intro"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("itemPic","itempic"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("submitDate","submittime"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("dayRent","dayrent"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("contactPhone","phone"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("contactWx","wxnumber"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("contactQq","qqnumber"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("rentWay","rentways"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("itemType","itemtype"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("isRent","conrent"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("sendAddress","address"));
        item = (JSONObject) JSON.parse(JSON.toJSONString(item).replace("outUserId","userid"));

        System.out.println(item);
        boolean result = itemserviceimp.addItem(item);
        System.out.println(result);

    }

}
